home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / incrementalSaveScene.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  7.3 KB  |  195 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  November 12 2000
  22. //
  23. //  Procedure Name:
  24. //        incrementalSaveScene
  25. //
  26. //  Description:
  27. //      Called when the scene is saved and the File->"Incremental Save"
  28. //      menu item is checked "on".
  29. //    
  30. //      Performs a non-destructive save of the current scene by taking the
  31. //        version of the scene that was last saved to disk and moving it to
  32. //        a subdirectory for scene "increments". The subdirectory where 
  33. //        increments are moved to will be created if it doesn't exist. 
  34. //        Each scene has its own directory for increments.
  35. //    
  36. //        If a past increment is opened and then saved with Incremental Save on,
  37. //        then it will become the newest version of the scene, and the scene that
  38. //        was previously newest (the one outside of the increments directory) 
  39. //        will now become a past increment.
  40. //    
  41. //        For example, if scenes\myScene.mb already exists, and is modified,
  42. //        then saving incrementally will cause the existing file to be moved into
  43. //        scenes\myScene.mb.backup\myScene.0001.mb, and then scenes\myScene.mb would be
  44. //        saved with the newest changes. If myScene.mb was subsequently saved again,
  45. //      then the previous version would be moved to scenes\myScene.mb.backup\myScene.0002.mb
  46. //    
  47. //        If myScene.0001.mb was then opened, modified, and saved, then
  48. //        scenes\myScene.mb would be moved to scenes\myScene.mb.backup\myScene.0003.mb
  49. //        and the current changes would be saved over scenes\myScene.mb.
  50. //        This is a means of reverting back to a previous version of a scene, while keeping
  51. //        the changes that were made in the mean time.
  52. //    
  53. //        With this scheme, the latest increment of a scene will always be in the 
  54. //        original scene file location (scenes\myScene.mb, for example).
  55. //
  56. //        NOTE: This procedure does not check for scene changes first; that is left
  57. //              to the caller.
  58. //
  59. //  Input Arguments:
  60. //        None
  61. //
  62. //  Return Value:
  63. //        None.
  64. //
  65. global proc incrementalSaveScene() 
  66. {
  67.     string $scenePath = `file -q -sceneName`;
  68.  
  69.     string $pathInfo[] = incrementalSaveProcessPath( $scenePath );
  70.     string $scenePath = $pathInfo[0];
  71.     string $sceneName = $pathInfo[1];
  72.     string $sceneExtension = $pathInfo[2];
  73.     string $sceneNamePrefix = $pathInfo[3];
  74.     string $currVersionString = $pathInfo[4];
  75.     string $incrementDirName = $pathInfo[5];
  76.  
  77.  
  78.     string $sceneToMove = $sceneNamePrefix + $sceneExtension;
  79.     string $incrementDirPath = $scenePath + $incrementDirName;
  80.  
  81.     // Make sure we have a directory to back-up our previous version into.
  82.     //
  83.     if(!`file -q -exists $incrementDirPath`)
  84.         sysFile -makeDir $incrementDirPath;
  85.  
  86.     $incrementDirPath = $incrementDirPath + "/";
  87.  
  88.     // Get the largest increment version for this scene from the increments directory.
  89.     // Iterate through all the file names that match our scene name, keeping track of 
  90.     // the highest increment value found.
  91.     //
  92.     string $existingIncrements[];
  93.     catch ( $existingIncrements = `getFileList 
  94.                 -folder $incrementDirPath 
  95.                 -filespec ($sceneNamePrefix + ".*" + $sceneExtension)` );
  96.  
  97.     $fileVersion = 0;
  98.     int $thisVersion;
  99.  
  100.     for($i = 0; $i < size($existingIncrements); $i++) {
  101.  
  102.         string $noExtension = `substring $existingIncrements[$i] 
  103.             1 (size($existingIncrements[$i]) - size($sceneExtension))`;
  104.  
  105.         $thisVersion = `match "[0-9]+$" $noExtension`;
  106.  
  107.         if($thisVersion > $fileVersion)
  108.             $fileVersion = $thisVersion;
  109.  
  110.     }
  111.  
  112.     string $newVersionString = $fileVersion + 1;
  113.  
  114.     // Make the increment-number in the filename to be at least 4 digits in length.
  115.     // Doing so makes sure that alphabetical ordering sorts the first 9999 increments.
  116.     //
  117.     int $i;
  118.     for($i = size($newVersionString); $i < 4; $i++)
  119.         $newVersionString = "0" + $newVersionString;
  120.  
  121.     // Build the name of the new scene
  122.     //
  123.     string $newSceneName = $sceneNamePrefix + "." + $newVersionString + $sceneExtension;
  124.     string $newScenePath = $incrementDirPath + $newSceneName;
  125.  
  126.     // Check to make sure our script isn't going to overwrite an existing file
  127.     // since this script should provide a non-destructive save. If this occurs,
  128.     // it is an error in this script's logic (ack!).
  129.     //
  130.     if(`file -q -exists $newScenePath`)
  131.         error ("Internal error in Incremental Save: should not be overwriting \""
  132.             + $newSceneName + "\"! Bailing out without save.");
  133.  
  134.  
  135.     // Check if this is read only and warn the user if necessary
  136.     //
  137.     string $pathToMove = ( $scenePath + $sceneToMove );
  138.     if ( !`filetest -w $pathToMove` ) {
  139.         // The original file is write protected
  140.         //
  141.         string $message = "Cannot save changes to read only file: " + $sceneToMove;
  142.         confirmDialog -button "OK" -message $message;
  143.         error $message;
  144.     }
  145.     // Copy the previous version into the incremental save directory
  146.     //
  147.     sysFile -move $newScenePath $pathToMove;
  148.  
  149.     // Save the new scene. We may be saving from a past increment, so make it
  150.     // save over the original scene name (now that the previous one has been 
  151.     // backed up to the increments directory).
  152.     //
  153.     if(`file -q -sceneName` != ($scenePath + $sceneToMove)) {
  154.         int $wasDefaultExtensions = `file -q -defaultExtensions`;
  155.         file -defaultExtensions false;
  156.         file -rename ($scenePath + $sceneToMove);
  157.         file -defaultExtensions $wasDefaultExtensions;
  158.     }
  159.  
  160.     // Print some useful information to the script editor so that users can
  161.     // find out exactly what has been done
  162.     //
  163.     print ( "// Performing Incremental Save:\n" );
  164.     print ( "//   master file:    " + $scenePath + $sceneToMove + "\n" );
  165.     print ( "//   increment file: " + $newScenePath + "\n" );
  166.  
  167.     evalEcho ("file -force -save -options \"v=0\"");
  168.  
  169.     // Now that we have made it this far, delete any old backups past the 
  170.     // number that the user has asked us to save
  171.     //
  172.  
  173.     // Look up whether we are limiting the number of backups saved, and if so,
  174.     // what the limit is
  175.     //
  176.     int $maxNumberBackups = -1;
  177.     if ( ( `optionVar -exists incrementalSaveLimitBackups` ) &&
  178.          ( `optionVar -exists incrementalSaveMaxBackups` ) )
  179.     {
  180.         if ( `optionVar -q incrementalSaveLimitBackups` ) {
  181.             $maxNumberBackups = `optionVar -q incrementalSaveMaxBackups`;
  182.         } 
  183.     }
  184.     if ( $maxNumberBackups >= 0 ) {
  185.         $existingIncrements = sort( $existingIncrements );
  186.         // Figure out how many backups to delete.  Adjust for the new backup that
  187.         // we just created.
  188.         //
  189.         int $last = ( size( $existingIncrements ) + 1 ) - $maxNumberBackups;
  190.         for ( $i = 0; $i < $last; $i++ ) {
  191.             sysFile -delete ( $incrementDirPath + $existingIncrements[$i] );
  192.         }
  193.     }
  194. }
  195.